<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Post data to jobs API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'ml-post-data.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ml-post-data.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ml-post-data.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/ml-post-data.html" rel="nofollow" target="_blank">../en/ml-post-data.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="ml-apis.html">Machine learning anomaly detection APIs</a></span>
»
<span class="breadcrumb-node">Post data to jobs API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="ml-open-job.html">« Open anomaly detection jobs API</a>
</span>
<span class="next">
<a href="ml-preview-datafeed.html">Preview datafeeds API »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="ml-post-data"></a>Post data to jobs API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>

<p>Sends data to an anomaly detection job for analysis.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST _ml/anomaly_detectors/&lt;job_id&gt;/_data</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-prereqs"></a>Prerequisites<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
If the Elasticsearch security features are enabled, you must have <code class="literal">manage_ml</code> or
<code class="literal">manage</code> cluster privileges to use this API. See
<a class="xref" href="security-privileges.html" title="Security privileges">Security privileges</a>.
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The job must have a state of <code class="literal">open</code> to receive and process the data.</p>
<p>The data that you send to the job must use the JSON format. Multiple JSON
documents can be sent, either adjacent with no separator in between them or
whitespace separated. Newline delimited JSON (NDJSON) is a possible whitespace
separated format, and for this the <code class="literal">Content-Type</code> header should be set to
<code class="literal">application/x-ndjson</code>.</p>
<p>Upload sizes are limited to the Elasticsearch HTTP receive buffer size
(default 100 Mb). If your data is larger, split it into multiple chunks
and upload each one separately in sequential time order. When running in
real time, it is generally recommended that you perform many small uploads,
rather than queueing data to upload larger files.</p>
<p>When uploading data, check the job data counts for progress.
The following documents will not be processed:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Documents not in chronological order and outside the latency window
</li>
<li class="listitem">
Records with an invalid timestamp
</li>
</ul>
</div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>For each job, data can only be accepted from a single connection at
a time. It is not currently possible to post data to multiple jobs using wildcards
or a comma-separated list.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-path-parms"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;job_id&gt;</code>
</span>
</dt>
<dd>
(Required, string)
Identifier for the anomaly detection job.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-query-parms"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">reset_start</code>
</span>
</dt>
<dd>
(Optional, string) Specifies the start of the bucket resetting range.
</dd>
<dt>
<span class="term">
<code class="literal">reset_end</code>
</span>
</dt>
<dd>
(Optional, string) Specifies the end of the bucket resetting range.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<p>A sequence of one or more JSON documents containing the data to be analyzed.
Only whitespace characters are permitted in between the documents.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ml-post-data-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ml/anomaly-detection/apis/post-data.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The following example posts data from the <code class="literal">it_ops_new_kpi.json</code> file to the
<code class="literal">it_ops_new_kpi</code> job:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">$ curl -s -H "Content-type: application/json"
-X POST http:\/\/localhost:9200/_ml/anomaly_detectors/it_ops_new_kpi/_data
--data-binary @it_ops_new_kpi.json</pre>
</div>
<p>When the data is sent, you receive information about the operational progress of
the job. For example:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
	"job_id":"it_ops_new_kpi",
	"processed_record_count":21435,
	"processed_field_count":64305,
	"input_bytes":2589063,
	"input_field_count":85740,
	"invalid_date_count":0,
	"missing_field_count":0,
	"out_of_order_timestamp_count":0,
	"empty_bucket_count":16,
	"sparse_bucket_count":0,
	"bucket_count":2165,
	"earliest_record_timestamp":1454020569000,
	"latest_record_timestamp":1455318669000,
	"last_data_time":1491952300658,
	"latest_empty_bucket_timestamp":1454541600000,
	"input_record_count":21435
}</pre>
</div>
<p>For more information about these properties, see <a class="xref" href="ml-get-job-stats.html#ml-get-job-stats-results" title="Response body">Response body</a>.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="ml-open-job.html">« Open anomaly detection jobs API</a>
</span>
<span class="next">
<a href="ml-preview-datafeed.html">Preview datafeeds API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>